package com.ybfenpan.controller.admin.member;


import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Daili;
import com.ybfenpan.service.DailiService;
import com.ybfenpan.utils.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * Created by Administrator on 2016/3/25.
 */
@Controller

public class DailiShowController extends BaseController {
    @Resource
    private DailiService dailiService;


    @RequestMapping("admin/member/dailiShow.shtml")
    public String show(HttpServletRequest request) throws Exception {
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
        if (0 < id) {
            Daili daili = dailiService.getByKey(id);

            request.setAttribute("daili", daili);
        }
        return "admin/member/dailiShow";

    }


    @RequestMapping("admin/member/dailiUpdate.shtml")
    public String update(Daili daili, HttpServletRequest request, ModelMap model) throws Exception {
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
//        daili.setCurrentLevel(null);
        if (0 < id) {

            dailiService.update(daili);
            setMessage(model, "更新成功！");
            request.setAttribute("daili", daili);

        }
        return "admin/member/dailiShow";
    }


}
